/*
 * DefaultActionEnabledCallback.java
 *
 *  
 */
package org.msb.finance.app;

/**
 * The {@code DefaultActionEnabledCallback} class is a trivial implementation of the {@link ActionEnabledCallback}
 * interface that always returns a set {@code boolean} value when queried. The set value defaults to {@code false} when
 * the instance is constructed, but can be changed by either using the constructor that takes a {@code boolean}
 * argument, or by using the {@link #setValue(boolean)} method.
 * 
 * @author Marc
 * 
 */
public class DefaultActionEnabledCallback implements ActionEnabledCallback {

	/**
	 * The value to be returned when this object is queried for the enabled state of an {@link Action} object.
	 */
	private boolean value;

	/**
	 * Constructs a new {@code DefaultActionEnabledCallback} instance with the default value ({@code false}).
	 */
	public DefaultActionEnabledCallback() {
		// This constructor must be declared so that it is available.
	}

	/**
	 * Constructs a new {@code DefaultActionEnabledCallback} instance with the specified value.
	 * 
	 * @param value
	 *            A {@code boolean} value to set as the enabled state to be returned.
	 */
	public DefaultActionEnabledCallback(final boolean value) {
		setValue(value);
	}

	/**
	 * Sets the enabled state to be returned to the provided value.
	 * 
	 * @param value
	 *            A {@code boolean} value to set.
	 */
	public void setValue(boolean value) {
		this.value = value;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.msb.finance.app.ActionEnabledCallback#isEnabled()
	 */
	public boolean isEnabled() {
		return this.value;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		} else if (null != obj && obj.getClass() == this.getClass()) {
			return ((DefaultActionEnabledCallback) obj).value == this.value;
		} else {
			return false;
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		return System.identityHashCode(this.getClass()) | (this.value ? 1 : 0);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return String.valueOf(this.value);
	}

}
